package mapper;

import Conn.Conn;
import com.alibaba.fastjson.JSONObject;
import jdk.swing.interop.SwingInterOpUtils;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListDate {
     /*
    类: ListDate
    方法: ListCP
    方法说明:
        并将查询结果 组成 Map 并保存成列表存入 Json 的 List 键下
     */
    private static PreparedStatement pstam;

    public JSONObject ListCP() {
        Conn conn = new Conn();
        JSONObject obj = new JSONObject();
        try{
            pstam = conn.getConn().prepareStatement("select * from test where design = 0 order by Id ");
            ResultSet resultSet = pstam.executeQuery();
            List<Map> list = new ArrayList<>();
            while (resultSet.next()){
                Map<String,String> map = new HashMap<>();
                map.put("id",resultSet.getString("ID"));
                map.put("name",resultSet.getString("name"));
                map.put("text",resultSet.getString("text"));
                map.put("data",resultSet.getString("data"));
                list.add(map);
            }
            obj.put("List",list);
            return obj;
//            System.out.println(list.get(0).get("name"));
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }

    }




}
